<?php

/**
 * sfGuardUser form.
 *
 * @package    form
 * @subpackage sf_guard_user
 * @version    SVN: $Id: sfGuardUserForm.class.php 13001 2008-11-14 10:45:32Z noel $
 */
class adminProfileForm extends BasesfGuardUserForm
{
  protected
    $pkName = null;

  public function configure()
  {
    parent::configure();
   


    unset(
      $this['last_login'],
      $this['created_at'],
      $this['salt'],
      $this['nickname'],
      $this['username'],
      $this['algorithm'],
      $this['is_active'],
      $this['is_super_admin'],
      $this['sf_guard_user_group_list'],
      $this['sf_guard_user_permission_list']
    );
    
     $lang = array('ru','en');
    
     $this->setWidgets(array(
      'id'              => new sfWidgetFormInputHidden(),
      'full_profile'        => new sfWidgetFormInputHidden(array(),array('value'=>'1')),
      'email'        => new sfWidgetFormInput(array(),array('size'=>25)),
      'password'        =>   new sfWidgetFormInputPassword(),
      
      	
     ));
                        $this->widgetSchema['partner_id'] =   new sfWidgetFormInputHidden(array(),array('size'=>7));
     
		 	/*
		 	 * примеры виджетов
		 	 */ 
		 	//$this->widgetSchema['zodiac'] = new sfWidgetFormChoice(array('expanded'=>true,'choices' => myTools::getZodiac()));
		 	//$this->widgetSchema['zodiac2'] = new sfWidgetFormChoice(array('expanded'=>false,'choices' => myTools::getZodiac()));
		 	//$this->widgetSchema['zodiac3'] = new sfWidgetFormChoice(array('multiple'=>true,'expanded'=>false,'choices' => myTools::getZodiac()));
		 	//$this->widgetSchema['zodiac4'] = new sfWidgetFormChoice(array('multiple'=>false,'expanded'=>false,'choices' => myTools::getZodiac()));
     
                        $this->widgetSchema['username'] = new sfWidgetFormInput(array(),array('size'=>35));
                        $this->widgetSchema['gender'] = new sfWidgetFormInputHidden(array(),array('size'=>35,'value'=>'w'));
                        $this->widgetSchema['first_name'] = new sfWidgetFormInput(array(),array('size'=>35));
                        $this->widgetSchema['last_name'] = new sfWidgetFormInput(array(),array('size'=>35));


		 	$this->widgetSchema['birthday'] = new sfWidgetFormI18nDate(array('culture' =>sfContext::getInstance()->getUser()->getCulture(),'years' => sfContext::getInstance()->getUser()->getYears()));
		
		 	$this->widgetSchema['height'] = new sfWidgetFormInput(array(),array('size'=>5));
		
		 	$this->widgetSchema['ves'] = new sfWidgetFormInput();
		
		 	$this->widgetSchema['city'] = new sfWidgetFormInput(array(),array('size'=>5));
		
		 	$this->widgetSchema['country'] = new sfWidgetFormI18nSelectCountry(array('culture' =>sfContext::getInstance()->getUser()->getCulture()));
				 	
		
		 	//$this->widgetSchema['eye_color'] = new sfWidgetFormChoice(array('expanded'=>'true','choices' => myTools::getEyeColor()));
		 	$this->widgetSchema['eye_color'] = new sfWidgetFormInput(array(),array('size'=>25));
		
		 	//$this->widgetSchema['hair_color'] = new sfWidgetFormChoice(array('expanded'=>'true','choices' => myTools::getHairColor()));
		 	$this->widgetSchema['hair_color'] = new sfWidgetFormInput(array(),array('size'=>25));
		

		
		 	$this->widgetSchema['religion'] = new sfWidgetFormChoice(array('expanded'=>false,'choices' => myTools::getReligion()));
		
		 	$this->widgetSchema['language'] = new sfWidgetFormI18nSelectLanguage(array('culture' => sfContext::getInstance()->getUser()->getCulture(),'languages'=>$lang));

                        if($this->getObject()->getId()>0){
                        $this->widgetSchema['add_language'] = new myWidgetLanguage(array(),array('user_id'=>$this->getObject()->getId()));
                        }

                        $this->widgetSchema['drinking'] = new sfWidgetFormInputCheckbox();
		
		 	$this->widgetSchema['smoking'] = new sfWidgetFormInputCheckbox();
		
		 	$this->widgetSchema['profession'] = new sfWidgetFormInput(array(),array('size'=>55));
		 	
		
		 	$this->widgetSchema['is_marital'] = new sfWidgetFormChoice(array('expanded'=>false,'choices' => myTools::getIsmarital()));
		
		 	$this->widgetSchema['have_child'] = new sfWidgetFormInputCheckbox();
		
		 	$this->widgetSchema['wants_children'] = new sfWidgetFormInputCheckbox();
		
		 	$this->widgetSchema['about_me'] = new sfWidgetFormTextarea(array(),array('style'=>'width:300px'));
		 	
		
		 	$this->widgetSchema['about_partner'] = new sfWidgetFormTextarea(array(),array('style'=>'width:300px'));
		
		 	
		
		 	$this->widgetSchema['photo'] =   new sfWidgetFormInputFile();
		
		 
		 
		
		 	$this->widgetSchema['introduction_letter'] = new sfWidgetFormTextarea(array(),array('width'=>400));
		 		 
		

			$age_from=$this->getObject()->getPartnerAgeFrom();
			$age_to=$this->getObject()->getPartnerAgeTo();
			$height_from=$this->getObject()->getPartnerHeightFrom();
			$height_to=$this->getObject()->getPartnerHeightTo();
			
		   $this->widgetSchema['partner_age_from_to'] = 
		   	new myRangeAgePartnerWidget(array('partner_age_from'=>new sfWidgetFormInput(array(),array('size'=>5)),
		   										'partner_age_to'=>new sfWidgetFormInput(array(),array('size'=>5))),
		   								array('partner_age_from'=>$age_from,
		   								'partner_age_to'=>$age_to));
		   $this->widgetSchema['partner_height_from_to'] = 
		   
		   	new myRangeHeightPartnerWidget(array('partner_height_from'=>new sfWidgetFormInput(array(),array('size'=>5)),
		   								'partner_height_to'=>new sfWidgetFormInput(array(),array('size'=>5))),
		   								array('partner_height_from'=>$height_from,
		   								'partner_height_to'=>$height_to));
					 			 	

		
      	
		 
		 //////////////////Мультики
		 
		     $this->setDefault('cmy_read',myTools::db_array_field($this->object->getMyRead())); 
		     $this->setDefault('cmy_musik',myTools::db_array_field($this->object->getMyMusik())); 
		     $this->setDefault('cmy_rest',myTools::db_array_field($this->object->getMyRest())); 
		     $this->setDefault('cmy_food',myTools::db_array_field($this->object->getMyFood())); 
		     $this->setDefault('cmy_sport',myTools::db_array_field($this->object->getMySport())); 
		     $this->setDefault('cmy_harakter',myTools::db_array_field($this->object->getMyHarakter()));
		 
		     
		     
  		$this->widgetSchema['is_online']= new sfWidgetFormInputCheckbox();
		 
		 		 
		 
		 
		 /*
		  * функции админа 
		  */
		 
		 if(sfContext::getInstance()->getUser()->isAuthenticated() and sfContext::getInstance()->getUser()->hasCredential('admin'))
    {
    	
    	  $this->widgetSchema['account'] =   new sfWidgetFormInput(array(),array('size'=>25));
		
    	  if(sfConfig::get('app_use_partner')==true)
		 {
    	   $this->widgetSchema['is_partner'] =   new sfWidgetFormInputCheckbox();
		 }	

    	  
			 
        
     
            
		 
       
		 
		 
		  if(sfConfig::get('app_form_pf_is_abon')==true)
		 {
    	   $this->widgetSchema['is_abon'] =   new sfWidgetFormInputCheckbox();
		 }
		 
		 
		 
    }
        $this->widgetSchema['is_top'] =   new sfWidgetFormInputCheckbox();
     	$this->validatorSchema ['photo'] = new sfValidatorFile ( array ('required' => false, 
		'path' => sfConfig::get ( 'sf_web_dir' ) . '/uploads/users/avatar', 
		'mime_types' => 'web_images', 'max_size' => 500000, // 360 kB
                'validated_file_class' => 'sfUserAvatarValidatedFile' ) );
     	
     	$this->validatorSchema ['password'] = new sfValidatorString(array('required' => false));
        $this->validatorSchema ['email'] = new sfValidatorString(array('required' => true));
        

     	
     	$this->validatorSchema ['birthday'] = new sfValidatorDate(array('required' => true));
     
    //  $this->mergePostValidator(new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'password_again', array(), array('invalid' => 'The two passwords must be the same.')));
     
    
	     $this->widgetSchema->setLabels(
    array(
      'username'  => __('Логин'),
      'nickname'    => __('Ник'),
      'ves'    => __('Вес'),
      'avatar'   => __('Аватар'),  
      'icq' => __('Номер ICQ'),
      'skype' => __('Номер skype'),
      'email'     => __('E-mail'),
      'password'  => __('Пароль'),
      'country' => __('Страна'),
      'gender' => __('Пол'),
      'birthday' => __('Дата рождения'),
      'password2' => __('Повтор пароля')
    )
    ); 
	    
	    //$this->widgetSchema->setFormFormatterName('list');       
    
        $custom_decorator = new sfWidgetFormSchemaFormatterDefList($this->getWidgetSchema());
        $this->getWidgetSchema()->addFormFormatter('deflist', $custom_decorator);
        $this->getWidgetSchema()->setFormFormatterName('deflist');
    
    
	     $this->validatorSchema->setOption('allow_extra_fields', true);
	     $this->widgetSchema->setNameFormat('user[%s]');
	     if(sfConfig::get('app_form_pf_i18n')==true)
	     {
		 $this->embedI18n(array('en', 'ru'));
	     }
	   
       
  }
}


class sfWidgetFormSchemaFormatterDefList extends sfWidgetFormSchemaFormatter {
    protected
      $rowFormat                 = '<div class="sf_admin_form_row">%label%%error%%field%%help%%hidden_fields%</div>',
      $helpFormat                = '<span class="help">%help%</span>',
      $errorRowFormat            = '<dt class="error">Errors:</dt><dd>%errors%</dd>',
      $errorListFormatInARow     = '<ul class="error_list">%errors%</ul>',
      $errorRowFormatInARow      = '<li>%error%</li>',
      $namedErrorRowFormatInARow = '<li>%name%: %error%</li>',
      $decoratorFormat           = '<dl id="formContainer">%content%</dl>';
}
